using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CoinUpgradeItem : MonoBehaviour
{
    public EasyEvent OnChanged = new EasyEvent();

    private CoinUpgradeItem mNext = null;

    public CoinUpgradeItem Next(CoinUpgradeItem next)
    {
        mNext = next;
        mNext.Condition(_=>UpgradeFinish);
        return mNext;
    }
    public bool UpgradeFinish { get;set; } = false;
    public string Key { get;private set; }
    public string Description { get; private set; }

    public int Price { get; private set; }

    public Func<CoinUpgradeItem, bool> mCondition;
    public void UpGrade()
    {
        TriggerOnChanged();
        mOnUpgrade?.Invoke(this);
        UpgradeFinish = true;
        CoinUpgradeSystem.OnCoinUpgradeSystemChanged.Trigger();
    }

    public void TriggerOnChanged()
    {
        OnChanged.Trigger();
        mNext?.TriggerOnChanged();
    }

    private Action<CoinUpgradeItem> mOnUpgrade;

    public bool ConditionCheck()
    {
        if(mCondition != null)
        {
            return !UpgradeFinish && mCondition.Invoke(this);
        }

        return !UpgradeFinish;
    }
    public CoinUpgradeItem WithKey(string key)
    {
        Key = key;
        return this;
    }
    public CoinUpgradeItem WithDescription(string description)
    {
        Description = description;
        return this;
    }
    public CoinUpgradeItem WithPirce(int price)
    {
        Price = price;
        return this;
    }
    public CoinUpgradeItem OnUpgrade(Action<CoinUpgradeItem> onUpgrade)
    {
        mOnUpgrade = onUpgrade;
        return this;
    }

    public CoinUpgradeItem Condition(Func<CoinUpgradeItem,bool> func)
    {
        mCondition = func;
        return this;
    }
}
